<template>
  <div class="app-container">
    <el-row>
        <el-col :span="4">
            <div class="grid-content bg-purple serchInput">
                <el-select v-model="dateType" placeholder="请选择" @change="fetchData()">
                  <el-option
                    v-for="item in options"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value">
                  </el-option>
                </el-select>
            </div>
        </el-col>
    </el-row>
    
    <el-table
      v-loading="listLoading"
      :data="list"
      element-loading-text="Loading"
      height="700"
      border
      fit
      highlight-current-row>
      <!-- <el-table-column align="center" label="ID" width="95">
        <template slot-scope="scope">
          {{ scope.$index }}
        </template>
      </el-table-column> -->
      <el-table-column label="统计日期" align="center">
        <template slot-scope="scope">
          {{ scope.row.statisticsDate }}
        </template>
      </el-table-column>
      <el-table-column label="统计纬度"  align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.dateType }}</span>
        </template>
      </el-table-column>
      <el-table-column label="活跃用户数"  align="center">
        <template slot-scope="scope">
          {{ scope.row.num }}
        </template>
      </el-table-column>
      <!-- <el-table-column class-name="status-col" label="Status" width="110" align="center">
        <template slot-scope="scope">
          <el-tag :type="scope.row.status | statusFilter">{{ scope.row.status }}</el-tag>
        </template>
      </el-table-column> -->
      <!-- <el-table-column align="center" prop="created_at" label="status" width="200">
        <template slot-scope="scope">
          <i class="el-icon-time" />
          <span>{{ scope.row.status }}</span>
        </template>
      </el-table-column> -->
    </el-table>
    <div class="block">
      <el-pagination
       
        layout="prev, pager, next"
        @current-change="handleCurrentChange"
        :total="total">
      </el-pagination>
    </div>
  </div>
</template>

<script>
import { getDauList } from '@/api/statistics'

export default {
  filters: {
    statusFilter(status) {
      const statusMap = {
        published: 'success',
        draft: 'gray',
        deleted: 'danger'
      }
      return statusMap[status]
    }
  },
  data() {
    return {
      list: null,
      total: 0,
      pageSize: 15,
      pageNum: 1,
      listLoading: true,
      options: [{
          value: 'day',
          label: '日活跃用户'
        }, {
          value: 'hour',
          label: '小时活跃用户'
        }
      ],
      dateType: 'day'
    }
  },
  created() {
    this.fetchData()
  },
  methods: {
    fetchData(param) {
      this.listLoading = true
      if (param == undefined) {
        param={
          // dateType: 'hour',
          pageNum: this.pageNum, 
          pageSize: this.pageSize,
          dateType: this.dateType
        }
      }
      getDauList(param).then(response => {
        this.listLoading = false
        console.log("response="+response.data)
        // this.list = response.data
        if (response.data) {
            this.list = response.data.list
            this.total = response.data.total
            this.pageNum = response.data.pageNum
            this.pageSize = response.data.pageSize
        }
      })
    },
    handleSizeChange(val) {
        console.log(`每页 ${val} 条`);
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      var param={
        pageNum:val, 
        pageSize:this.pageSize,
        dateType: this.dateType
      }
      console.log(`当前页: `+JSON.stringify(param));
      this.fetchData(param)
    }
  }
}
</script>
